/*
* Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
*/
package com.laihuichuxing.producerAndConsumer;

import java.util.concurrent.BlockingQueue;

/**
 * Description:
 *
 * @author: Qinxuefeng
 * @since: 1.0
 * Create Date Time: 2018/12/12 14:58
 * Update Date Time:
 */

public class Consumer implements Runnable{
    private final int id;
    BlockingQueue<Product> consumerQueue;

    public Consumer(BlockingQueue<Product> productQueue,int id ) {
        super();
        this.id = id;
        this.consumerQueue = productQueue;
    }

    @Override
    public String toString() {
        return "Consumer{" +
                "id=" + id +
                '}';
    }

    @Override
    public void run() {
        try{
            while(!Thread.interrupted()){
                Product consumerProduct = consumerQueue.take();
                System.out.println("消费者"+this+"消费了：" + consumerProduct);
            }
        }catch (InterruptedException e){
            e.toString();
        }
    }
}
